/*------------------------------------------------------------------------------*\
**
**  adventure_map_window_base.h
**
**			Heroes IV
**	  Copyright 2001, The 3DO Company
**
\*------------------------------------------------------------------------------*/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "adventure_map_window_base.h"

#include "adventure_map.h"
#include "adventure_frame.h"
#include "convert_16_bit.h"
#include "map_renderer.h"

t_adventure_map_window_base::t_adventure_map_window_base ( t_screen_rect const& rect, t_adventure_frame* frame_ptr, 
                t_window* parent_ptr )
                      : t_window( k_no_transparency, parent_ptr ),
					    t_map_renderer( *frame_ptr->get_map() ),
					    m_map( frame_ptr->get_map() ), m_frame( frame_ptr )
{
}

t_adventure_map& t_adventure_map_window_base::get_map() 
{
	return *m_map;
}

t_adventure_map const& t_adventure_map_window_base::get_map() const
{
	return *m_map;
}

// ------------------------------------------------------------------------
// window to display an adventure map
// move view, and limit to acceptable ranges
// ------------------------------------------------------------------------
void t_adventure_map_window_base::move_view( t_screen_point point )
{
	t_screen_point view_size = get_view_size();
	t_screen_point map_size  = m_map->get_view_size();

	if (point.x < -50)
		point.x = -50;
	if (point.y < -k_max_tile_vertex_height - 50)
		point.y = -k_max_tile_vertex_height - 50;
	if (point.x + view_size.x > map_size.x + 50)
		point.x = map_size.x + 50 - view_size.x ;
	if (point.y + view_size.y > map_size.y + 50)
		point.y = map_size.y + 50 - view_size.y;
	t_map_renderer::move_view( point );
}

// ------------------------------------------------------------------------
// window to display an adventure map
// ------------------------------------------------------------------------
void t_adventure_map_window_base::center_view( t_screen_point point )
{
	t_screen_point view_size = get_view_size();

	point -= view_size / 2;
	move_view( point );
	m_frame->set_view_level( get_view_level() );
}

// ------------------------------------------------------------------------
// window to display an adventure map
// ------------------------------------------------------------------------
void t_adventure_map_window_base::center_view( t_level_map_point_2d const& point )
{
	t_screen_point screen_point = m_map->get_screen_point( point );

	screen_point.y -= m_map->get_tile_vertex( point ).get_height();
	center_view( screen_point );
	m_frame->set_view_level( point.level );
}

void t_adventure_map_window_base::paint( t_paint_surface& paint_surface )
{
}

t_abstract_bitmap16_ptr t_adventure_map_window_base::create_back_buffer( t_screen_point const & view_size )
{
	m_back_buffer = new t_memory_bitmap16( view_size.x, view_size.y );
	return m_back_buffer;
}

void t_adventure_map_window_base::on_rects_dirtied( std::vector< t_screen_rect > const & dirtied_rects )
{
}

void t_adventure_map_window_base::on_view_moved( int new_view_level, t_screen_point const & new_view_pos, 
		                                    t_screen_point const & new_view_size )
{
}

